package com.example.myglidedemo;

import androidx.appcompat.app.AppCompatActivity;

import android.graphics.drawable.Drawable;
import android.os.Bundle;
import android.widget.ImageView;

import com.bumptech.glide.Glide;
import com.bumptech.glide.load.model.GlideUrl;
import com.bumptech.glide.request.FutureTarget;
import com.bumptech.glide.request.RequestOptions;
import com.example.myglidedemo.options.GlideApp;

import java.util.concurrent.ExecutionException;

public class MainActivity extends AppCompatActivity {
    //
    ImageView ivPic;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        ivPic = findViewById(R.id.iv_pic);

        //GlideModule 在rebuild Module 后会生成一些工具代码

        //RequestOptions requestOptions = new RequestOptions().centerCrop();
        //  替换Glide.with() 的写法
//        GlideApp.with(this)
//                .load("http://cn.bing.com/az/hprichbg/rb/Dongdaemun_ZH-CN10736487148_1920x1080.jpg")
//                //.apply(requestOptions)
//                .applyAvatar(144*2)  // 调用自己写的
//                .into(ivPic);

        // 实现异步加载
//        FutureTarget<Drawable> target=GlideApp.with(this)
//                .asDrawable()
//                .load("http://cn.bing.com/az/hprichbg/rb/Dongdaemun_ZH-CN10736487148_1920x1080.jpg")
//                .applyAvatar(144*3)
//                .submit();
//        new Thread(new Runnable() {
//            @Override
//            public void run() {
//                try {
//                    Drawable drawable = target.get();
//                    //切回主线程
//                    runOnUiThread(new Runnable() {
//
//                        @Override
//                        public void run() {
//                            ivPic.setImageDrawable(drawable);
//                        }
//                    });
//                } catch (Exception e) {
//                    e.printStackTrace();
//                }
//
//            }
//        }).start();

        GlideApp.with(this)
                .MycrossFade()
                .load("http://cn.bing.com/az/hprichbg/rb/Dongdaemun_ZH-CN10736487148_1920x1080.jpg")
                .applyAvatar(144*3)
                .into(ivPic)
                ;





   }


}